package com.zhangkang.stock.stocklib.view

import com.zhangkang.stock.stocklib.view.index.KLineTurnOver
import com.zhangkang.stock.stocklib.view.index.KLineViewKDJ
import com.zhangkang.stock.stocklib.view.index.KLineViewMACD
import com.zhangkang.stock.stocklib.view.index.KLineViewRSI
import com.zhangkang.stock.stocklib.view.index.KLineVolume

/**
 * @author : Android-张康
 * created on: 2023/5/10 21:42
 * description:
 */
internal class IndexInfoListHelper(
    private val pathPool: PathPool,
    private val rectPool: RectPool,
    private val kLineViewColor: KLineViewColor,
    private val kLineViewDimen: KLineViewDimen,
    private val indexNameConfig: IndexNameConfig
) {
    private val defaultList =
        listOf(
            KLineIndex.Volume,
            KLineIndex.TurnOver,
            KLineIndex.MACD,
            KLineIndex.RSI,
            KLineIndex.KDJ
        )

    fun nextIndex(currentIndex: KLineIndexInfo): KLineIndexInfo {
        var findIndex = -1
        defaultList.forEachIndexed { index, kLineIndex ->
            if (kLineIndex == currentIndex.getKLineIndex()) {
                findIndex = index
                return@forEachIndexed
            }
        }
        if (findIndex == -1) {
            return currentIndex
        }
        if (findIndex >= defaultList.size - 1) {
            return createKLineIndexInfo(defaultList[0])
        }
        return createKLineIndexInfo(defaultList[findIndex + 1])
    }

    fun createKLineIndexInfo(kLineIndex: KLineIndex): KLineIndexInfo {
        return when (kLineIndex) {
            KLineIndex.BOLL -> TODO()
            KLineIndex.KDJ -> {
                KLineViewKDJ(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.KLine -> {
                KLineKLine(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.MACD -> {
                KLineViewMACD(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.RSI -> {
                KLineViewRSI(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.TurnOver -> {
                KLineTurnOver(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }

            KLineIndex.Volume -> {
                KLineVolume(pathPool, rectPool, kLineViewColor, kLineViewDimen, indexNameConfig)
            }
        }
    }

}